/*
 * DefaultEditorFactory.java
 */

package xq.swing;

import java.io.File;
import java.io.IOException;

/**
 *
 * @author ThorntonRP
 */
public class DefaultEditorFactory implements EditorFactory {

	public boolean acceptsContentType(String contentType) {
		return contentType.startsWith("text/");
	}

	public Editor createEditor(String contentType) {
		if (acceptsContentType(contentType)) {
			Editor editor = new Editor(contentType);
			editor.setName("New Text Document");
			return editor;
		} else {
			throw new IllegalArgumentException("Unsupported content type: " + contentType);
		}
	}

	public Editor createEditor(String contentType, File f) throws IOException {
		if (acceptsContentType(contentType)) {
			Editor editor = new Editor(contentType, f);
			editor.setName(f.getName());
			return editor;
		} else {
			throw new IllegalArgumentException("Unsupported content type: " + contentType);
		}
	}
}
